<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>acutil: src/strutil_inl.h源文件</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body onload='searchBox.OnSelectItem(0);'>
<!-- 制作者 Doxygen 1.7.4 -->
<script type="text/javascript"><!--
var searchBox = new SearchBox("searchBox", "search",false,'搜索');
--></script>
<div id="top">
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">acutil</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>首页</span></a></li>
      <li><a href="namespaces.html"><span>名字空间</span></a></li>
      <li class="current"><a href="files.html"><span>文件</span></a></li>
      <li id="searchli">
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="搜索" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>文件列表</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<div class="title">src/strutil_inl.h</div>  </div>
</div>
<div class="contents">
<a href="strutil__inl_8h.html">浏览该文件的文档。</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 ﻿
<a name="l00005"></a>00005 <span class="preprocessor">#pragma once</span>
<a name="l00006"></a>00006 <span class="preprocessor"></span><span class="preprocessor">#include &lt;string&gt;</span>
<a name="l00007"></a>00007 <span class="preprocessor">#include &lt;algorithm&gt;</span>
<a name="l00008"></a>00008 <span class="preprocessor">#include &lt;functional&gt;</span>
<a name="l00009"></a>00009 <span class="preprocessor">#include &quot;base/platform.h&quot;</span>
<a name="l00010"></a>00010 
<a name="l00011"></a>00011 <span class="keyword">namespace </span>acutil{
<a name="l00012"></a>00012   <span class="keyword">namespace </span>string{
<a name="l00013"></a>00013     <span class="keyword">namespace </span>internal{
<a name="l00014"></a>00014       <span class="keywordtype">void</span> <a class="code" href="namespaceacutil_1_1string_1_1internal.html#aa77c9f32b1443e47e608508f73788aef">Trim</a>(std::string&amp; s);
<a name="l00015"></a>00015       <span class="keywordtype">void</span> <a class="code" href="namespaceacutil_1_1string_1_1internal.html#aa77c9f32b1443e47e608508f73788aef">Trim</a>(std::wstring&amp; s);
<a name="l00016"></a>00016     }
<a name="l00017"></a>00017 
<a name="l00018"></a>00018     <span class="keyword">template</span> &lt;<span class="keyword">typename</span> CharT, <span class="keyword">typename</span> StringContainer&gt;
<a name="l00019"></a><a class="code" href="namespaceacutil_1_1string.html#a42cebc0ae4c28cdb3182e618385cafd5">00019</a>     std::basic_string&lt;CharT&gt; <a class="code" href="namespaceacutil_1_1string.html#a42cebc0ae4c28cdb3182e618385cafd5" title="将string_list 内所有字符串以seperator 为间隔串联起来">Join</a>(<span class="keyword">const</span> StringContainer&amp; string_list, <span class="keyword">const</span> std::basic_string&lt;CharT&gt;&amp; seperator){
<a name="l00020"></a>00020       std::basic_string&lt;CharT&gt; s_r;
<a name="l00021"></a>00021       std::basic_string&lt;CharT&gt;::size_type size_r = seperator.size() * string_list.size();
<a name="l00022"></a>00022       StringContainer::const_iterator it = string_list.begin();
<a name="l00023"></a>00023       <span class="keywordflow">for</span> (; it != string_list.end(); ++it){
<a name="l00024"></a>00024         size_r += it-&gt;size();
<a name="l00025"></a>00025       }
<a name="l00026"></a>00026       s_r.reserve(size_r);
<a name="l00027"></a>00027       <span class="keywordflow">for</span> (it = string_list.begin(); it != string_list.end(); ++it){
<a name="l00028"></a>00028         <span class="keywordflow">if</span> (it != string_list.begin())
<a name="l00029"></a>00029           s_r.insert(s_r.end(), seperator.begin(), seperator.end());
<a name="l00030"></a>00030         s_r.insert(s_r.end(), it-&gt;begin(), it-&gt;end());
<a name="l00031"></a>00031       }
<a name="l00032"></a>00032       <span class="keywordflow">return</span> AC_STDMOVE(s_r);
<a name="l00033"></a>00033     }
<a name="l00034"></a>00034 
<a name="l00035"></a>00035     <span class="keyword">template</span> &lt;<span class="keyword">typename</span> CharT&gt;
<a name="l00036"></a><a class="code" href="namespaceacutil_1_1string.html#a2da9dd644aa10e6eb9ae128e4dafc1d7">00036</a>     std::basic_string&lt;CharT&gt; <a class="code" href="namespaceacutil_1_1string.html#a2da9dd644aa10e6eb9ae128e4dafc1d7" title="将字符串s 中所有字符按照(A-Z)=&gt;(a-z) 的对应关系全部转化为小写">Lower</a>(<span class="keyword">const</span> std::basic_string&lt;CharT&gt;&amp; s){
<a name="l00037"></a>00037       std::basic_string&lt;CharT&gt; s_r;
<a name="l00038"></a>00038       s_r.resize(s.size());
<a name="l00039"></a>00039       std::transform(s.begin(), s.end(), s_r.begin(), tolower);
<a name="l00040"></a>00040       <span class="keywordflow">return</span> AC_STDMOVE(s_r);
<a name="l00041"></a>00041     }
<a name="l00042"></a>00042 
<a name="l00043"></a>00043     <span class="keyword">template</span> &lt;<span class="keyword">typename</span> CharT&gt;
<a name="l00044"></a><a class="code" href="namespaceacutil_1_1string.html#ad5709ef2fefc7bed7be85efe434c1b2d">00044</a>     std::basic_string&lt;CharT&gt; <a class="code" href="namespaceacutil_1_1string.html#ad5709ef2fefc7bed7be85efe434c1b2d" title="将字符串s 中所有字符按照(a-z)=&gt;(A-Z) 的对应关系全部转化为大写">Upper</a>(<span class="keyword">const</span> std::basic_string&lt;CharT&gt;&amp; s){
<a name="l00045"></a>00045       std::basic_string&lt;CharT&gt; s_r;
<a name="l00046"></a>00046       s_r.resize(s.size());
<a name="l00047"></a>00047       std::transform(s.begin(), s.end(), s_r.begin(), toupper);
<a name="l00048"></a>00048       <span class="keywordflow">return</span> AC_STDMOVE(s_r);
<a name="l00049"></a>00049     }
<a name="l00050"></a>00050 
<a name="l00051"></a>00051     <span class="keyword">template</span> &lt;<span class="keyword">typename</span> CharT&gt;
<a name="l00052"></a><a class="code" href="namespaceacutil_1_1string.html#a305a8e63c81de2b38195f0f7a834737d">00052</a>     <span class="keywordtype">void</span> <a class="code" href="namespaceacutil_1_1string.html#a305a8e63c81de2b38195f0f7a834737d" title="与 Lower() 功能相类似,只是 ToLower() 是对字符串进行原地修改">ToLower</a>(std::basic_string&lt;CharT&gt;&amp; s){
<a name="l00053"></a>00053       std::transform(s.begin(), s.end(), s.begin(), tolower);
<a name="l00054"></a>00054     }
<a name="l00055"></a>00055 
<a name="l00056"></a>00056     <span class="keyword">template</span> &lt;<span class="keyword">typename</span> CharT&gt;
<a name="l00057"></a><a class="code" href="namespaceacutil_1_1string.html#adfc7fa59c511e4c4d795366743142de9">00057</a>     <span class="keywordtype">void</span> <a class="code" href="namespaceacutil_1_1string.html#adfc7fa59c511e4c4d795366743142de9" title="与 Upper() 功能相类似,只是 ToUpper() 是对字符串进行原地修改">ToUpper</a>(std::basic_string&lt;CharT&gt;&amp; s){
<a name="l00058"></a>00058       std::transform(s.begin(), s.end(), s.begin(), toupper);
<a name="l00059"></a>00059     }
<a name="l00060"></a>00060 
<a name="l00061"></a>00061     <span class="keyword">template</span> &lt;<span class="keyword">typename</span> CharT&gt;
<a name="l00062"></a><a class="code" href="namespaceacutil_1_1string.html#ac59b0baa9f7f7f5e57dad928545252a1">00062</a>     <span class="keywordtype">void</span> <a class="code" href="namespaceacutil_1_1string.html#ac59b0baa9f7f7f5e57dad928545252a1" title="删除s 首部多余的字符,多余字符列表由trim_chars 指定">TrimStart</a>(std::basic_string&lt;CharT&gt;&amp; s, <span class="keyword">const</span> std::basic_string&lt;CharT&gt;&amp; trim_chars){
<a name="l00063"></a>00063       s.erase(0, s.find_first_not_of(trim_chars.c_str(), trim_chars.size()));
<a name="l00064"></a>00064     }
<a name="l00065"></a>00065 
<a name="l00066"></a>00066     <span class="keyword">template</span> &lt;<span class="keyword">typename</span> CharT&gt;
<a name="l00067"></a><a class="code" href="namespaceacutil_1_1string.html#a40f65b3dbb8410d5b6a92fc9cfea3aef">00067</a>     <span class="keywordtype">void</span> <a class="code" href="namespaceacutil_1_1string.html#a40f65b3dbb8410d5b6a92fc9cfea3aef" title="删除s 尾部多余的字符,多余字符列表由trim_chars 指定">TrimEnd</a>(std::basic_string&lt;CharT&gt;&amp; s, <span class="keyword">const</span> std::basic_string&lt;CharT&gt;&amp; trim_chars){
<a name="l00068"></a>00068       s.erase(s.find_last_not_of(trim_chars.c_str(), trim_chars.size()) + 1);
<a name="l00069"></a>00069     }
<a name="l00070"></a>00070 
<a name="l00071"></a>00071     <span class="keyword">template</span> &lt;<span class="keyword">typename</span> CharT&gt;
<a name="l00072"></a><a class="code" href="namespaceacutil_1_1string.html#a4598cbba42dbcfcf5723c7c889d228c1">00072</a>     <span class="keywordtype">void</span> <a class="code" href="namespaceacutil_1_1string.html#a4598cbba42dbcfcf5723c7c889d228c1" title="删除s 首部与尾部多余的字符,多余字符列表由trim_chars 指定">Trim</a>(std::basic_string&lt;CharT&gt;&amp; s, <span class="keyword">const</span> std::basic_string&lt;CharT&gt;&amp; trim_chars){
<a name="l00073"></a>00073       <a class="code" href="namespaceacutil_1_1string.html#a40f65b3dbb8410d5b6a92fc9cfea3aef" title="删除s 尾部多余的字符,多余字符列表由trim_chars 指定">TrimEnd</a>(s, trim_chars);
<a name="l00074"></a>00074       <a class="code" href="namespaceacutil_1_1string.html#ac59b0baa9f7f7f5e57dad928545252a1" title="删除s 首部多余的字符,多余字符列表由trim_chars 指定">TrimStart</a>(s, trim_chars);
<a name="l00075"></a>00075     }
<a name="l00076"></a>00076 
<a name="l00077"></a>00077     <span class="keyword">template</span> &lt;<span class="keyword">typename</span> CharT, <span class="keyword">typename</span> Predicate&gt;
<a name="l00078"></a><a class="code" href="namespaceacutil_1_1string.html#a9edec33cd15f06c02e89105cd347ed5f">00078</a>     <span class="keywordtype">void</span> <a class="code" href="namespaceacutil_1_1string.html#a9edec33cd15f06c02e89105cd347ed5f" title="和 Trim_Start() 功能类似,不过是否删除字符是由pred(c)指定的,如果其返回false,则结束Trim过程">TrimStart_If</a>(std::basic_string&lt;CharT&gt;&amp; s, <span class="keyword">const</span> Predicate&amp; pred){
<a name="l00079"></a>00079       std::basic_string&lt;CharT&gt;::iterator it = s.begin();
<a name="l00080"></a>00080       <span class="keywordflow">for</span> (; it &lt; s.end(); ++it)
<a name="l00081"></a>00081         <span class="keywordflow">if</span> (!pred(*it))
<a name="l00082"></a>00082           <span class="keywordflow">break</span>;
<a name="l00083"></a>00083       s.erase(s.begin(), it);
<a name="l00084"></a>00084     }
<a name="l00085"></a>00085 
<a name="l00086"></a>00086     <span class="keyword">template</span> &lt;<span class="keyword">typename</span> CharT, <span class="keyword">typename</span> Predicate&gt;
<a name="l00087"></a><a class="code" href="namespaceacutil_1_1string.html#a3e2ddb9574c70c38c91158b6d691efb1">00087</a>     <span class="keywordtype">void</span> <a class="code" href="namespaceacutil_1_1string.html#a3e2ddb9574c70c38c91158b6d691efb1" title="和 Trim_End() 功能类似,不过是否删除字符是由pred(c)指定的,如果其返回false,则结束Trim过程">TrimEnd_If</a>(std::basic_string&lt;CharT&gt;&amp; s, <span class="keyword">const</span> Predicate&amp; pred){
<a name="l00088"></a>00088       std::basic_string&lt;CharT&gt;::reverse_iterator it = s.rbegin();
<a name="l00089"></a>00089       <span class="keywordflow">for</span> (; it &lt; s.rend(); ++it)
<a name="l00090"></a>00090         <span class="keywordflow">if</span> (!pred(*it))
<a name="l00091"></a>00091           <span class="keywordflow">break</span>;
<a name="l00092"></a>00092       s.erase(it.base(), s.end());
<a name="l00093"></a>00093     }
<a name="l00094"></a>00094 
<a name="l00095"></a>00095     <span class="keyword">template</span> &lt;<span class="keyword">typename</span> CharT, <span class="keyword">typename</span> Predicate&gt;
<a name="l00096"></a><a class="code" href="namespaceacutil_1_1string.html#ace2ff30b92333c032d6ff0ede915f4a9">00096</a>     <span class="keywordtype">void</span> <a class="code" href="namespaceacutil_1_1string.html#ace2ff30b92333c032d6ff0ede915f4a9" title="和 Trim() 功能类似,不过是否删除字符是由pred(c)指定的,如果其返回false,则结束Trim过程">Trim_If</a>(std::basic_string&lt;CharT&gt;&amp; s, <span class="keyword">const</span> Predicate&amp; pred){
<a name="l00097"></a>00097       <a class="code" href="namespaceacutil_1_1string.html#a40f65b3dbb8410d5b6a92fc9cfea3aef" title="删除s 尾部多余的字符,多余字符列表由trim_chars 指定">TrimEnd</a>(s, pred);
<a name="l00098"></a>00098       <a class="code" href="namespaceacutil_1_1string.html#ac59b0baa9f7f7f5e57dad928545252a1" title="删除s 首部多余的字符,多余字符列表由trim_chars 指定">TrimStart</a>(s, pred);
<a name="l00099"></a>00099     }
<a name="l00100"></a>00100 
<a name="l00101"></a>00101     <span class="keyword">template</span> &lt;<span class="keyword">typename</span> CharT&gt;
<a name="l00102"></a><a class="code" href="namespaceacutil_1_1string.html#a6445f70a2e7e028c6bb1f53b85216717">00102</a>     <span class="keywordtype">void</span> <a class="code" href="namespaceacutil_1_1string.html#a4598cbba42dbcfcf5723c7c889d228c1" title="删除s 首部与尾部多余的字符,多余字符列表由trim_chars 指定">Trim</a>(std::basic_string&lt;CharT&gt;&amp; s) {
<a name="l00103"></a>00103       <a class="code" href="namespaceacutil_1_1string_1_1internal.html#aa77c9f32b1443e47e608508f73788aef">internal::Trim</a>(s);
<a name="l00104"></a>00104     }
<a name="l00105"></a>00105 
<a name="l00106"></a>00106 <span class="preprocessor">#ifdef AC_RVALUE_REF</span>
<a name="l00107"></a>00107 <span class="preprocessor"></span>    <span class="keyword">template</span> &lt;<span class="keyword">typename</span> CharT&gt;
<a name="l00108"></a>00108     std::basic_string&lt;CharT&gt; <a class="code" href="namespaceacutil_1_1string.html#a2da9dd644aa10e6eb9ae128e4dafc1d7" title="将字符串s 中所有字符按照(A-Z)=&gt;(a-z) 的对应关系全部转化为小写">Lower</a>(std::basic_string&lt;CharT&gt;&amp;&amp; s){
<a name="l00109"></a>00109       <a class="code" href="namespaceacutil_1_1string.html#a305a8e63c81de2b38195f0f7a834737d" title="与 Lower() 功能相类似,只是 ToLower() 是对字符串进行原地修改">ToLower</a>(s);
<a name="l00110"></a>00110       <span class="keywordflow">return</span> s;
<a name="l00111"></a>00111     }
<a name="l00112"></a>00112 
<a name="l00113"></a>00113     <span class="keyword">template</span> &lt;<span class="keyword">typename</span> CharT&gt;
<a name="l00114"></a>00114     std::basic_string&lt;CharT&gt; <a class="code" href="namespaceacutil_1_1string.html#ad5709ef2fefc7bed7be85efe434c1b2d" title="将字符串s 中所有字符按照(a-z)=&gt;(A-Z) 的对应关系全部转化为大写">Upper</a>(std::basic_string&lt;CharT&gt;&amp;&amp; s){
<a name="l00115"></a>00115       <a class="code" href="namespaceacutil_1_1string.html#adfc7fa59c511e4c4d795366743142de9" title="与 Upper() 功能相类似,只是 ToUpper() 是对字符串进行原地修改">ToUpper</a>(s);
<a name="l00116"></a>00116       <span class="keywordflow">return</span> s;
<a name="l00117"></a>00117     }
<a name="l00118"></a>00118 <span class="preprocessor">#endif // AC_RVALUE_REF</span>
<a name="l00119"></a>00119 <span class="preprocessor"></span>  }
<a name="l00120"></a>00120 }
</pre></div></div>
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>全部</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>名字空间</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>文件</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>函数</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<hr class="footer"/><address class="footer"><small>Generated at 2011年四月11日 星期一 00:05:04 for acutil by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
</body>
</html>
